package com.clinic.accessor.db;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.clinic.entity.db.DrugIssue;
import com.clinic.entity.param.Index;

@Component
public class DrugIssueAccessor extends AbstractDbAccessor<DrugIssue> {

	public DrugIssue getDrugIssueById(long id) {
		DetachedCriteria criteria = DetachedCriteria.forClass(DrugIssue.class);
		criteria.add(Restrictions.eq(DrugIssue.Columns.DRUG_ISSUE_ID, id));
		return uniqueGeneric(criteria);
	}
	
	public List<DrugIssue> getDrugIssuesByPrescriptionId(long prescriptionId, Index index) {
		DetachedCriteria criteria = DetachedCriteria.forClass(DrugIssue.class);
		criteria.add(Restrictions.eq("prescription.prescriptionId", prescriptionId));
		return listGeneric(criteria, index);
	}
	
	public List<DrugIssue> getDrugIssuesByDrugId(long drugId, Index index) {
		DetachedCriteria criteria = DetachedCriteria.forClass(DrugIssue.class);
		criteria.add(Restrictions.eq("drug.drugId", drugId));
		return listGeneric(criteria, index);
	}
	
}
